package PrinterSource;

import Backend.PrinterAgent;
import Models.PrinterModel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.snmp4j.smi.OID;

public class QueryHandler {

    public static PrinterManager manager;

    public QueryHandler() {
        try {
            manager = new PrinterManager();

        } catch (IOException ex) {
            Logger.getLogger(QueryHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static ArrayList<String> get_printers() {
        //Returns a list of active printers
        if (!manager.models.isEmpty()) {
            ArrayList<String> list = new ArrayList<String>();
            for (int i = 0; i < manager.models.size(); i++) {
                list.add(manager.getData(i, PrinterAgent.name));
            }
            return list;
        }

        return new ArrayList<String>();
    }

    public static String[] get_printer_byName(String printername) {
        //Returns a list of active printers

        int index = manager.getDevice(printername);
        if (index < manager.models.size()) {
            return manager.getDetails(index);
        }
        return null;
    }

    public static ArrayList<String[]> get_Network() {
        return manager.getNetworkDetails();
    }

    public static void set_Val(String printername, OID oid, String val) {
        //Returns a list of active printers
        int index = manager.getDevice(printername);
        manager.setData(index, oid, val);
    }
//    
//    public static PrinterModel get_printer_byIP(String printerIP){
//        //Returns a list of active printers
//        for(int i=0; i< manager.models.size();i++){
//            if(manager.models.get(i).getIP().matches(printerIP)){
//                return manager.models.get(i);
//            }
//        }
//        return new PrinterModel();
//    }
}